<?php
/**
 * 个人信息更改
 * @author tsbtjy@gmail.com
 *
 */
class DefaultController extends Controller
{
	public $layout='//layouts/column2';
	
	private $_model;
	
	public function actionIndex()
	{
		$model = $this->loadModel();
		$this->render('index',array(
			'model'=>$model,
		));
	}
	
	public function actionUpdate()
	{
		$model = $this->loadModel();
		if(isset($_POST['User']))
		{
			$model->attributes=$_POST['User'];
			if($model->save())
			{
				return $this->actionIndex();
			}
		}else{
			$this->render('update',array(
			'form'=>$model,
			));
		}
	}
	
	public function loadModel()
	{
		if($this->_model===null)
		{
			$this->_model=User::model()->findbyPk(Yii::app()->user->id);
			if($this->_model===null)
				throw new CHttpException(404,'The requested page does not exist.');
		}
		return $this->_model;
	}
	
}